//#include "myhead.h"
#include <stdio.h>
#include <pthread.h>
void *fun1(void *arg)
{
	while(1)
	{
		printf("我是1号\n");
		sleep(1);
	}
	
	//pthread_exit("线程退出了");
}

void *fun2(void *arg)
{
	while(1)
	{
		printf("我是2号\n");
		sleep(1);
	}
	
	//pthread_exit("线程退出了");
}

void *fun3(void *arg)
{
	while(1)
	{
		printf("我是3号\n");
		sleep(1);
	}
	
	//pthread_exit("线程退出了");
}
int main()
{
	//保存静态优先级的结构体
	struct sched_param myparam;
	myparam.sched_priority = 55;  //最低
	
	struct sched_param myparam2;
	myparam2.sched_priority = 1;
	
	struct sched_param myparam3;
	myparam3.sched_priority = 98;
	pthread_t id1,id2,id3;
	//定义属性变量并初始化
	pthread_attr_t myattr,myattr2,myattr3;
	pthread_attr_init(&myattr);
	pthread_attr_init(&myattr2);
	pthread_attr_init(&myattr3);
	
	pthread_attr_setschedpolicy(&myattr,SCHED_FIFO);//调度策略
	int ret = pthread_attr_setschedparam(&myattr,&myparam);//优先级
	printf("ret=%d\n",ret);
	if(ret!=0)
	{
		printf("优先级1失败\n");
	}
	
	//创建第一个线程使用刚才设置的属性
	pthread_create(&id1,&myattr,fun1,NULL);
	
	pthread_attr_setschedpolicy(&myattr2,SCHED_FIFO);//调度策略
	int ret2 = pthread_attr_setschedparam(&myattr2,&myparam2);//优先级
	printf("ret2=%d\n",ret2);
	if(ret2!=0)
	{
		printf("优先级55失败\n");
	}
	//创建第二个线程使用刚才设置的属性
	pthread_create(&id2,&myattr2,fun2,NULL);
		
	pthread_attr_setschedpolicy(&myattr3,SCHED_FIFO);//调度策略
	int ret3 = pthread_attr_setschedparam(&myattr3,&myparam3);//优先级
	printf("ret3=%d\n",ret3);
	if(ret3!=0)
	{
		printf("优先级98失败\n");
		
	}
	
	//创建第三个线程使用刚才设置的属性
	pthread_create(&id3,&myattr3,fun3,NULL);	
	
	while(1);
	
	//销毁线程的属性
	pthread_attr_destroy(&myattr);
}